<script>

export default {
  globalData: {
    baseUrl: 'https://we9.91gongju.cn:10000',
    //baseUrl: 'https://localhost:10000',
    a: {},
    globalHandleLogin: function (e) {
      console.log('获取信息', e);
      var that = this;
      that.login();
      that.userInfoData = e.detail.userInfo;
      uni.setStorageSync('userInfo', e.detail.userInfo);
      uni.setStorageSync('openid', e.detail.userInfo.openid);
      uni.setStorageSync('nick_name', e.detail.userInfo.nickName);
      uni.setStorageSync('avatar_url', e.detail.userInfo.avatarUrl);
      uni.setStorageSync('gender', e.detail.userInfo.gender); //if (!e.detail.userInfo) {
      //   that.globalData.userInfoData =e.detail.userInfo
      //   wx.setStorageSync('userInfo', e.detail.userInfo)
      //   wx.setStorageSync('openid', e.detail.userInfo.openid);
      //   wx.setStorageSync('nick_name', e.detail.userInfo.nickName);
      //   wx.setStorageSync('avatar_url', e.detail.userInfo.avatarUrl);
      //   wx.setStorageSync('gender', e.detail.userInfo.gender);
      // } else if (wx.getStorageSync('userInfo')) {
      //   that.globalData.userInfoData = wx.getStorageSync('userInfo')
      // }
    },
    login: function () {
      var that = this;
      uni.login({
        success(res) {
          console.log('login调用成功', res.code);
          var code = res.code;
          uni.request({
            url: `https://we9.91gongju.cn:10000/oauth/wx/getOpenid/${code}`,
            //url: `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx022815589dbefd3e&redirect_uri=http://we7.91gongju.cn/api.php?id=1&response_type=code&scope=snsapi_userinfo&&connect_redirect=1#wechat_redirect`,
            method: 'GET',
            dataType: 'json',
            header: {
              'content-type': 'application/json'
            },
            success: res => {
              console.log('成功获取openid', JSON.parse(res.data.message).openid);
              uni.setStorageSync('openid', JSON.parse(res.data.message).openid);
              uni.request({
                url: `${that.baseUrl}/user/selectIsUser/${uni.getStorageSync('openid')}`,
                // 目标服务器url
                method: 'GET',
                dataType: 'json',
                header: {
                  'content-type': 'application/json'
                },
                success: res => {
                  console.log('数据库中是否存在用户数据', res.data);

                  if (res.data.message === '用户不存在') {
                    that.register();
                  } else {
                    that.userInfoData = uni.getStorageSync('userInfo'); // wx.request({
                    //   url: `${app.globalData.baseUrl}/message/count/${res.data.dataMap.data.id}`,
                    //   success(res1) {
                    //     console.log("message: " + res1.data.dataMap.data);
                    //     that.setData({message: res1.data.dataMap.data})
                    //   }
                    // })
                  }
                }
              });
            },

            fail(res) {
              console.log('获取openid失败');
            }

          });
        },

        fail(res) {
          console.log(`login调用失败`);
        }

      });
    },
    register: function () {
      uni.request({
        url: `https://we9.91gongju.cn:10000/user/register`,
        // 目标服务器url
        method: 'POST',
        dataType: 'json',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          openid: uni.getStorageSync('openid'),
          nickName: uni.getStorageSync('nick_name'),
          avatarUrl: uni.getStorageSync('avatar_url'),
          gender: uni.getStorageSync('gender')
        },
        success: res => {
          var constant = res.data.message;
          this.invatation();
          this.addIntegral();
        }
      });
    },
    addIntegral: function () {
      uni.request({
        url: `https://we9.91gongju.cn:10000/user/getInfo/${uni.getStorageSync('openid')}`,
        header: {
          'content-type': 'application/json'
        },
        method: 'GET',
        dataType: 'json',
        success: result => {
          uni.request({
            url: `https://we9.91gongju.cn:10000/integral/addIntegral/${result.data.dataMap.data.id}`,
            method: 'POST',
            dataType: 'json',
            success: result => {
              console.log('添加积分调用成功', result);
            },
            fail: () => {
              console.log('添加积分调用失败');
            }
          });
        },
        fail: () => {}
      });
    },

    invatation() {
      let a = this.a;

      if (a.refUser) {
        uni.request({
          url: `https://we9.91gongju.cn:10000/integral`,
          complete: b => {},
          data: {
            "category": "1",
            "origin": "邀请用户",
            "user": a.r,
            "value": 2
          },
          method: "POST",
          success: b => {
            uni.request({
              url: `https://we9.91gongju.cn:10000/message/save`,
              complete: c => {},
              data: {
                "message": "邀请用户",
                "user": a.r
              },
              fail: c => {},
              method: "POST",
              success: c => {
                uni.hideLoading({
                  complete: d => {
                    uni.showToast({
                      title: '被邀请成功'
                    });
                  }
                });
              }
            });
          }
        });
      }
    }

  },

  /**
   * 当小程序初始化完成时，会触发 onLaunch（全局只触发一次）
   */
  onLaunch: function (z) {
    let a = z.query;
    this.globalData.a = a;
  },

  /**
   * 当小程序启动，或从后台进入前台显示，会触发 onShow
   */
  onShow: function (options) {
    console.log(options);
  },
  methods: {}
};
</script>
<style>
@import "./ttui/ttui.css";

.f-icontext {
    font-size: 22rpx;
}

.f-caption {
    font-size: 24rpx;
}

.f-caption-lg {
    font-size: 26rpx;
}

.f-paragraph {
    font-size: 28rpx;
}

.f-title {
    font-size: 30rpx;
}

.f-title-lg {
    font-size: 32rpx;
}

.f-title-xl {
    font-size: 48rpx;
}

.c-base {
    color: #ffffff;
}

.c-primary {
    color: #19a918;
}

.c-success {
    color: #19a918;
}

.c-warning {
    color: #feb22d;
}

.c-error {
    color: #fa3a39;
}

.c-hot {
    color: #ea3341;
}

.c-important {
    color: #ff3b30;
}

.c-disabled {
    color: #dddddd;
}

.c-placeholder {
    color: #aaa;
}

.c-black {
    color: #000;
}

.c-title {
    color: #576b95;
}

.c-paragraph {
    color: #222;
}

.c-caption {
    color: #888888;
}

.c-link {
    color: #108ee9;
}

.c-shadow {
    text-shadow: 2rpx 2rpx 2rpx #808080;
}

text {
    vertical-align: middle;
}

.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-justify {
    text-align: justify;
}

.text-justify::after {
    content: '';
    width: 100%;
    display: inline-block;
}

.text-delete {
    text-decoration: line-through;
}

.text-underline {
    text-decoration: underline;
}

.text-bold {
    font-weight: bold;
}

.text-price::before {
    content: "¥";
    font-size: 80%;
    margin-right: 4rpx;
}

.ellipsis {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.ellipsis-1 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.ellipsis-2 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.ellipsis-3 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}

.ellipsis-4 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
}

.fill-base {
    background: #ffffff;
}

.fill-body {
    background: #efeff5;
}

.fill-primary {
    background: #067aff;
}

.fill-success {
    background: #6abf47;
}

.fill-warning {
    background: #f86e21;
}

.fill-error {
    background: #f4333c;
}

.fill-hot {
    background: #f96268;
}

.fill-important {
    background: #ff3b30;
}

.fill-disabled {
    background: #dddddd;
}

.mg-sm {
    margin: 8rpx;
}

.mg-md {
    margin: 16rpx;
}

.mg-lg {
    margin: 32rpx;
}

.mt-sm {
    margin-top: 8rpx;
}

.mt-md {
    margin-top: 16rpx;
}

.mt-lg {
    margin-top: 32rpx;
}

.mr-sm {
    margin-right: 8rpx;
}

.mr-md {
    margin-right: 16rpx;
}

.mr-lg {
    margin-right: 32rpx;
}

.mb-sm {
    margin-bottom: 8rpx;
}

.mb-md {
    margin-bottom: 16rpx;
}

.mb-lg {
    margin-bottom: 32rpx;
}

.ml-sm {
    margin-left: 8rpx;
}

.ml-md {
    margin-left: 16rpx;
}

.ml-lg {
    margin-left: 32rpx;
}

.pd-sm {
    padding: 8rpx;
}

.pd-md {
    padding: 16rpx;
}

.pd-lg {
    padding: 32rpx;
}

.pt-sm {
    padding-top: 8rpx;
}

.pt-md {
    padding-top: 16rpx;
}

.pt-lg {
    padding-top: 32rpx;
}

.pr-sm {
    padding-right: 8rpx;
}

.pr-md {
    padding-right: 16rpx;
}

.pr-lg {
    padding-right: 32rpx;
}

.pb-sm {
    padding-bottom: 8rpx;
}

.pb-md {
    padding-bottom: 16rpx;
}

.pb-lg {
    padding-bottom: 32rpx;
}

.pl-sm {
    padding-left: 8rpx;
}

.pl-md {
    padding-left: 16rpx;
}

.pl-lg {
    padding-left: 32rpx;
}

.icon-xs {
    width: 22rpx;
    height: 22rpx;
    display: block;
}

.icon-right {
    width: 28rpx;
    height: 28rpx;
    display: block;
}

.icon-sm {
    width: 30rpx;
    height: 30rpx;
    display: block;
}

.icon-md {
    width: 40rpx;
    height: 40rpx;
    display: block;
}

.icon-lg {
    width: 50rpx;
    height: 50rpx;
    display: block;
}

.icon-xl {
    width: 60rpx;
    height: 60rpx;
    display: block;
}

.space-sm {
    height: 8rpx;
}

.space-md {
    height: 16rpx;
}

.space-lg {
    height: 32rpx;
}

.space {
    border-bottom: 1px solid rgba(216,216,216,0.5);
}

button {
    font-size: 32rpx;
}

button[plain] {
    color: #353535;
    border: 1px solid #353535;
    background-color: transparent;
}

button[type=primary][plain] {
    color: #19a918;
    border: 1px solid #19a918;
    background-color: transparent;
}

button[type=primary] {
    color: #fff;
    background-color: #19a918;
}

button[type=primary]::after {
    border: none;
}

button[type=warn][plain] {
    color: #e8bc79;
    border: 1px solid #e8bc79;
    background-color: transparent;
}

button[type=warn] {
    color: #fff;
    background-color: #e7bc77;
}

button[type=warn]::after {
    border: none;
}

button[type=default] {
    color: #000;
    background-color: #fff;
}

.wx-switch-input {
    transform: scale(0.9);
}

checkbox {
    transform: scale(0.9);
}

radio {
    transform: scale(0.9);
}

.flex {
    display: flex;
}

.flex-1 {
    flex: 1;
}

.flex-column {
    display: flex;
    flex-direction: column;
}

.flex-warp {
    display: flex;
    flex-wrap: wrap;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-x-center {
    display: flex;
    justify-content: center;
}

.flex-x-between {
    display: flex;
    justify-content: space-between;
}

.flex-y-center {
    display: flex;
    align-items: center;
}

.flex-y-start {
    display: flex;
    align-items: flex-start;
}

.flex-y-end {
    display: flex;
    align-items: flex-end;
}

.flex-y-baseline {
    display: flex;
    align-items: baseline;
}

.b-1px,.b-1px-t,.b-1px-b,.b-1px-tb,.b-1px-l,.b-1px-r {
    position: relative;
}

.b-1px:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 200%;
    border: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    height: 200%;
    transform-origin: left top;
    transform: scale(0.5);
    box-sizing: border-box;
}

.b-1px-t:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    height: 1px;
    border-top: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    transform-origin: 0 0;
    transform: scaley(0.5);
    box-sizing: border-box;
}

.b-1px-b:after {
    content: " ";
    position: absolute;
    left: 0;
    bottom: 0;
    right: 0;
    height: 1px;
    border-bottom: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    transform-origin: 0 100%;
    transform: scaley(0.5);
    box-sizing: border-box;
}

.b-1px-tb:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    height: 1px;
    border-top: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    transform-origin: 0 0;
    transform: scaley(0.5);
    box-sizing: border-box;
}

.b-1px-tb:after {
    content: " ";
    position: absolute;
    left: 0;
    bottom: 0;
    right: 0;
    height: 1px;
    border-bottom: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    transform-origin: 0 100%;
    transform: scaley(0.5);
    box-sizing: border-box;
}

.b-1px-l::before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    bottom: 0;
    border-left: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    transform-origin: 0 0;
    transform: scalex(0.5);
    box-sizing: border-box;
}

.b-1px-r::after {
    content: " ";
    position: absolute;
    right: 0;
    top: 0;
    width: 1px;
    bottom: 0;
    border-right: 1px solid rgba(238,238,238,1);
    color: rgba(238,238,238,1);
    transform-origin: 100% 0;
    transform: scalex(0.5);
    box-sizing: border-box;
}

.right-arrow {
    width: 0;
    height: 0;
    border: 8px solid;
    border-color: transparent transparent transparent #c7c7cc;
    position: relative;
    transform: translateX(8px);
}

.right-arrow::after {
    content: '';
    width: 0;
    height: 0;
    border: 8px solid;
    border-color: transparent transparent transparent #fff;
    position: absolute;
    left: -9px;
    top: -8px;
}

.right-arrow_sm {
    width: 0;
    height: 0;
    border: 6px solid;
    border-color: transparent transparent transparent #c7c7cc;
    position: relative;
    transform: translateX(6px);
}

.right-arrow_sm::after {
    content: '';
    width: 0;
    height: 0;
    border: 6px solid;
    border-color: transparent transparent transparent #fff;
    position: absolute;
    left: -7px;
    top: -6px;
}

.down-arrow {
    display: inline-block;
    position: relative;
    width: 40rpx;
    height: 30rpx;
    margin-right: 20rpx;
}

.down-arrow::after {
    display: inline-block;
    content: " ";
    height: 18rpx;
    width: 18rpx;
    border-width: 0 2rpx 2rpx 0;
    border-color: #999;
    border-style: solid;
    transform: matrix(0.71,0.71,-0.71,0.71,0,0);
    transform-origin: center;
    transition: transform 0.3s;
    position: absolute;
    top: 50%;
    right: 10rpx;
    margin-top: -10rpx;
}

.upload-add {
    position: relative;
    width: 150rpx;
    height: 150rpx;
    border: 1px solid #d9d9d9;
}

.upload-add:before {
    width: 5rpx;
    height: 64rpx;
}

.upload-add:before,.upload-add:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    background-color: #ddd;
}

.upload-add:after {
    width: 64rpx;
    height: 5rpx;
}

.upload-add:before,.upload-add:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    background-color: #ddd;
}

page {
    font-size: 30rpx;
    color: #222;
    line-height: 1.5;
    background: #efeff5;
    font-family: -apple-system,"SF UI Text",Roboto,Noto,"Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
}

view {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

image {
    width: 100%;
    height: 100%;
    display: block;
}

.h-full {
    height: 100%;
}

::-webkit-scrollbar {
    width: 0;
    height: 0;
    color: transparent;
}

.share-btn {
    margin: 0;
    padding: 0;
    background: transparent;
    line-height: 1.5;
    border: none;
    text-align: left;
}

.share-btn::after {
    border: none;
}

.mask-body {
    display: flex;
    flex-direction: column;
    z-index: 10001;
    width: 100%;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
    position: fixed;
    align-items: center;
    justify-content: center;
}

.cell-list {
    background: #fff;
    padding: 0 32rpx;
}

.cell-list-title {
    color: #888;
    background: #efeff5;
    height: 60rpx;
    display: flex;
    align-items: center;
    padding: 0 32rpx;
    font-size: 26rpx;
}

.cell-item {
    display: flex;
    align-items: center;
    padding: 16rpx 0;
}

.cell {
    display: flex;
    align-items: center;
    min-height: 90rpx;
    background: #fff;
}

.cell-label {
    width: 160rpx;
}

.form-item {
    display: flex;
    align-items: center;
    height: 90rpx;
    padding: 0 32rpx;
    background: #fff;
}

.form-avatar {
    display: flex;
    align-items: center;
    padding: 32rpx;
    background: #fff;
}

.form-label {
    width: 160rpx;
}

.form-img_tag {
    background: #e74d45;
    opacity: 0.7;
    width: 100%;
    height: 30%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24rpx;
    color: #fff;
    position: absolute;
    bottom: 0;
}

.fixed-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.avatar {
    width: 96rpx;
    height: 96rpx;
    border-radius: 6rpx;
}

.avatar-sm {
    width: 80rpx;
    height: 80rpx;
    border-radius: 6rpx;
    display: block;
}

.opacity-5 {
    opacity: 0.5;
}

.logo {
    width: 260rpx;
    height: 120rpx;
    margin: 10rpx 245rpx;
}

.nav-box {
    position: fixed;
    top: 75vh;
    right: 0;
    background: rgba(0,0,0,0.5);
    width: 100rpx;
    height: 100rpx;
    border-radius: 10rpx 0 0 10rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fefefe;
    font-size: 22rpx;
    z-index: 200;
}

.message-icon {
    position: fixed;
    bottom: 100rpx;
    right: 30rpx;
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
    box-shadow: 0 5rpx 10rpx rgba(0,0,0,0.1);
    z-index: 10;
}

.r-avatar {
    width: 90rpx;
    height: 90rpx;
    border-radius: 6rpx;
}

.r-avatar-sm {
    width: 50rpx;
    height: 50rpx;
    border-radius: 50%;
}

.tabbar-height {
    min-height: 110rpx;
    height: calc(110rpx + env(safe-area-inset-bottom) / 2);
}

/* 自定义 */
.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
} 
.wxParse-img {
  display: block !important;
}
.constant-space {
  height:20rpx;
  background-color: #F2f2f2;
}
.safeAreaOldPaddingBttom {
  padding-bottom: env(safe-area-inset-bottom);
}
.safeAreaNewPaddingBttom{
  padding-bottom: constant(safe-area-inset-bottom);  
}

.safeAreaOldMarginBttom {
  margin-bottom: env(safe-area-inset-bottom);
}
.safeAreaNewMarginBttom{
  margin-bottom: constant(safe-area-inset-bottom);  
}

.no-data {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.no-data .constant-line {
  width:132rpx;
  height:2rpx;
  background: #999;
}
.no-data .txt {
  font-size:26rpx;
  color:rgba(153,153,153,1);
  margin: 0 16rpx;
}
.ad-img {
  width: 100vw;
}

</style>